"use strict";
const common_vendor = require("../../../common/vendor.js");
const api_evaluation_index = require("../../../api/evaluation/index.js");
const stores_userInfo = require("../../../stores/userInfo.js");
const utils_tools = require("../../../utils/tools.js");
if (!Array) {
  const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
  const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
  const _easycom_qiun_data_charts2 = common_vendor.resolveComponent("qiun-data-charts");
  const _easycom_uni_th2 = common_vendor.resolveComponent("uni-th");
  const _easycom_uni_tr2 = common_vendor.resolveComponent("uni-tr");
  const _easycom_uni_td2 = common_vendor.resolveComponent("uni-td");
  const _easycom_uni_table2 = common_vendor.resolveComponent("uni-table");
  const _easycom_up_toast2 = common_vendor.resolveComponent("up-toast");
  (_easycom_up_icon2 + _easycom_up_input2 + _easycom_qiun_data_charts2 + _easycom_uni_th2 + _easycom_uni_tr2 + _easycom_uni_td2 + _easycom_uni_table2 + _easycom_up_toast2)();
}
const _easycom_up_icon = () => "../../../node-modules/uview-plus/components/u-icon/u-icon.js";
const _easycom_up_input = () => "../../../node-modules/uview-plus/components/u-input/u-input.js";
const _easycom_qiun_data_charts = () => "../../../uni_modules/qiun-data-charts/components/qiun-data-charts/qiun-data-charts.js";
const _easycom_uni_th = () => "../../../uni_modules/uni-table/components/uni-th/uni-th.js";
const _easycom_uni_tr = () => "../../../uni_modules/uni-table/components/uni-tr/uni-tr.js";
const _easycom_uni_td = () => "../../../uni_modules/uni-table/components/uni-td/uni-td.js";
const _easycom_uni_table = () => "../../../uni_modules/uni-table/components/uni-table/uni-table.js";
const _easycom_up_toast = () => "../../../node-modules/uview-plus/components/u-toast/u-toast.js";
if (!Math) {
  (_easycom_up_icon + _easycom_up_input + _easycom_qiun_data_charts + _easycom_uni_th + _easycom_uni_tr + _easycom_uni_td + _easycom_uni_table + _easycom_up_toast)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  setup(__props) {
    const userInfoStore = stores_userInfo.useUserInfoStore();
    const uToastRef = common_vendor.ref(null);
    const data = common_vendor.reactive({
      showPicker: false,
      queryParam: {
        type: 0,
        // 0按月 1按年
        yearMonth: common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY-MM"),
        policeLeaderId: userInfoStore.userInfo.userId,
        communityId: null
      },
      timeStr: common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY年MM月"),
      tableList: []
    });
    const { showPicker, queryParam, timeStr, tableList } = common_vendor.toRefs(data);
    const evaluationChart = common_vendor.reactive({
      chartData: {},
      opts: {
        animation: false,
        // 关闭动画
        update: true,
        // 关键：是否开启连续更新数据的方法,开启之后就不会抖动了
        duration: 0,
        // 关闭动画过度
        rotate: false,
        rotateLock: false,
        color: ["#39FB00", "#4AABFF", "#F55300"],
        padding: [10, 10, 10, 10],
        dataLabel: true,
        enableScroll: false,
        legend: {
          show: false
        },
        title: {},
        subtitle: {
          name: ""
        },
        extra: {
          ring: {
            ringWidth: 20,
            //圆环的宽度
            centerColor: "#ffffff",
            //中间填充圆形的颜色
            activeOpacity: 0.5,
            //启用Tooltip点击时，突出部分的透明度
            activeRadius: 8,
            //启用Tooltip点击时，突出部分的宽度
            offsetAngle: 0,
            //起始角度偏移度数，顺时针方向，
            labelWidth: 15,
            //数据标签到饼图外圆连线的长度
            border: false
            //是否绘制各类别中间的分割线
          }
        }
      }
    });
    const chartParam = common_vendor.reactive({
      opts: {
        animation: false,
        // 关闭动画
        update: true,
        // 关键：是否开启连续更新数据的方法,开启之后就不会抖动了
        duration: 0,
        // 关闭动画过度
        padding: [10, 0, 0, 0],
        enableScroll: false,
        legend: { show: false },
        dataLabel: false,
        // 不显示数据标签
        xAxis: {
          disableGrid: true,
          //不绘制纵向网格
          fontColor: "#000000",
          //字体颜色
          fontSize: 12,
          //字体大小
          axisLineColor: "#707070",
          //坐标轴轴线颜色
          marginTop: "5"
          //X轴文字距离轴线的距离
        },
        yAxis: {
          disableGrid: true,
          //不绘制横向向网格
          data: [
            {
              min: 0,
              calibration: true,
              //刻度线是否显示
              fontColor: "#8A8A8A",
              //字体颜色
              axisLineColor: "#707070"
              //坐标轴轴线颜色
            }
          ]
        },
        extra: {
          column: {
            type: "group",
            width: 10,
            linearType: "custom",
            //渐变类型
            customColor: ["#88C5EC", "#4299FE"],
            activeBgColor: "#000000",
            //当前点击柱状图的背景颜色
            activeBgOpacity: 0.08
            //当前点击柱状图的背景颜色透明度
          }
        }
      },
      chartData: {}
    });
    const getEvaluationStat = () => {
      api_evaluation_index.evaluationStat(queryParam.value).then((res) => {
        const { data: data2 } = res;
        renderPieChart(data2);
        tableList.value = data2.communityTableVos ?? [];
        if (queryParam.value.type == 1) {
          data2.yearStatisticsVos = data2.yearStatisticsVos ?? [];
          let xdata = [];
          let ydata = [];
          data2.yearStatisticsVos = data2.yearStatisticsVos ?? [];
          if (data2.yearStatisticsVos.length) {
            data2.yearStatisticsVos.forEach((item) => {
              xdata.push(item.month);
              ydata.push(item.monthCount - 0);
            });
          }
          let chartData = {
            categories: xdata,
            series: [
              {
                name: "评价次数",
                data: ydata
              }
            ]
          };
          chartParam.chartData = JSON.parse(JSON.stringify(chartData));
        }
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const updateEvaluationStat = (mode) => {
      queryParam.value.type = mode;
      if (mode == 0) {
        queryParam.value.yearMonth = common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY-MM");
        timeStr.value = common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY年MM月");
      } else {
        queryParam.value.yearMonth = common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY");
        timeStr.value = common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY年");
      }
      getEvaluationStat();
    };
    const bindPickerChange = (e) => {
      if (e.detail.value.includes("-")) {
        queryParam.value.yearMonth = e.detail.value.split("-")[0] + "-" + e.detail.value.split("-")[1];
        timeStr.value = e.detail.value.split("-")[0] + "年" + e.detail.value.split("-")[1] + "月";
      } else {
        queryParam.value.yearMonth = e.detail.value;
        timeStr.value = e.detail.value + "年";
      }
      getEvaluationStat();
    };
    const renderPieChart = (data2) => {
      let seriesData = {
        series: [
          {
            data: [
              {
                name: "满意",
                value: 0,
                labelText: `满意：0%`
              },
              {
                name: "一般",
                value: 0,
                labelText: `一般：0%`
              },
              {
                name: "不满意",
                value: 0,
                labelText: `不满意：0%`
              }
            ]
          }
        ]
      };
      let title = {
        name: 0,
        fontSize: 25,
        color: "#000000"
      };
      if (data2.sumCount > 0) {
        seriesData = {
          series: [
            {
              data: [
                {
                  name: "满意",
                  value: data2.satisfiedCount - 0,
                  labelText: `满意：${utils_tools.toFixedWithoutTrailingZeros(
                    data2.satisfiedCount / (data2.sumCount - 0) * 100
                  )}%`
                },
                {
                  name: "一般",
                  value: data2.generalCount - 0,
                  labelText: `一般：${utils_tools.toFixedWithoutTrailingZeros(
                    data2.generalCount / (data2.sumCount - 0) * 100
                  )}%`
                },
                {
                  name: "不满意",
                  value: data2.dissatisfiedCount - 0,
                  labelText: `不满意：${utils_tools.toFixedWithoutTrailingZeros(
                    data2.dissatisfiedCount / (data2.sumCount - 0) * 100
                  )}%`
                }
              ]
            }
          ]
        };
        title = {
          name: data2.sumCount - 0,
          fontSize: 25,
          color: "#000000"
        };
      }
      evaluationChart.chartData = JSON.parse(JSON.stringify(seriesData));
      evaluationChart.opts.title = JSON.parse(JSON.stringify(title));
    };
    const scanDetail = (row) => {
      common_vendor.index.navigateTo({
        url: `/subPages/leader/serviceEvaluation/detail?detailInfo=${JSON.stringify(
          row
        )}&type=${queryParam.value.type}&yearMonth=${queryParam.value.yearMonth}`
      });
    };
    common_vendor.onMounted(() => {
      getEvaluationStat();
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.n(common_vendor.unref(queryParam).type == 0 ? "opt-btn opt-btn-active" : "opt-btn opt-btn-unactive"),
        b: common_vendor.o(($event) => updateEvaluationStat(0)),
        c: common_vendor.n(common_vendor.unref(queryParam).type == 1 ? "opt-btn opt-btn-active" : "opt-btn opt-btn-unactive"),
        d: common_vendor.o(($event) => updateEvaluationStat(1)),
        e: common_vendor.p({
          name: "arrow-down",
          color: "#000000",
          size: "18"
        }),
        f: common_vendor.o(($event) => common_vendor.isRef(timeStr) ? timeStr.value = $event : null),
        g: common_vendor.p({
          disabled: true,
          disabledColor: "#ffffff",
          placeholder: "请选择",
          border: "none",
          color: "#000000",
          placeholderStyle: "{color: '#707070'}",
          modelValue: common_vendor.unref(timeStr)
        }),
        h: common_vendor.unref(queryParam).type == 0 ? "month" : "year",
        i: common_vendor.unref(queryParam).yearMonth,
        j: common_vendor.o(bindPickerChange),
        k: common_vendor.o(($event) => showPicker.value = false),
        l: common_vendor.o(($event) => showPicker.value = true),
        m: common_vendor.p({
          type: "ring",
          opts: common_vendor.unref(evaluationChart).opts,
          chartData: common_vendor.unref(evaluationChart).chartData
        }),
        n: common_vendor.unref(queryParam).type == 1
      }, common_vendor.unref(queryParam).type == 1 ? {
        o: common_vendor.p({
          type: "column",
          opts: common_vendor.unref(chartParam).opts,
          tooltipFormat: "normalTooltip",
          chartData: common_vendor.unref(chartParam).chartData
        })
      } : {}, {
        p: common_vendor.p({
          align: "center",
          width: "85"
        }),
        q: common_vendor.p({
          align: "center",
          width: "70"
        }),
        r: common_vendor.p({
          align: "center",
          width: "50"
        }),
        s: common_vendor.p({
          align: "center",
          width: "50"
        }),
        t: common_vendor.p({
          align: "center",
          width: "60"
        }),
        v: common_vendor.f(common_vendor.unref(tableList), (item, index, i0) => {
          return {
            a: common_vendor.t(item.communityName),
            b: "975f7d49-12-" + i0 + "," + ("975f7d49-11-" + i0),
            c: common_vendor.t(item.cmySumCount),
            d: common_vendor.o(($event) => scanDetail(item), index),
            e: "975f7d49-13-" + i0 + "," + ("975f7d49-11-" + i0),
            f: common_vendor.t(item.cmySatisfiedCount),
            g: "975f7d49-14-" + i0 + "," + ("975f7d49-11-" + i0),
            h: common_vendor.t(item.cmyGeneralCount),
            i: "975f7d49-15-" + i0 + "," + ("975f7d49-11-" + i0),
            j: common_vendor.t(item.cmyDissatisfiedCount),
            k: "975f7d49-16-" + i0 + "," + ("975f7d49-11-" + i0),
            l: index,
            m: "975f7d49-11-" + i0 + ",975f7d49-4"
          };
        }),
        w: common_vendor.p({
          align: "center"
        }),
        x: common_vendor.p({
          align: "center"
        }),
        y: common_vendor.p({
          align: "center"
        }),
        z: common_vendor.p({
          align: "center"
        }),
        A: common_vendor.p({
          align: "center"
        }),
        B: common_vendor.sr("table", "975f7d49-4"),
        C: common_vendor.p({
          border: true,
          stripe: true,
          emptyText: "暂无更多数据"
        }),
        D: common_vendor.n(common_vendor.unref(queryParam).type == 0 ? "mt-4_a_25" : "mt-1"),
        E: common_vendor.sr(uToastRef, "975f7d49-17", {
          "k": "uToastRef"
        })
      });
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-975f7d49"]]);
wx.createPage(MiniProgramPage);
